<%--
  Created by IntelliJ IDEA.
  User: zmjha
  Date: 2020/6/19
  Time: 20:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登陆</title>
</head>
<body>
<div style="align-content: center">
    <div id="mesg" style="color: darkorange"></div>
    用户名：<input type="text" id="username" ><br>
    密  码：<input type="password" id="password"><br>
    <button type="button" onclick="login()">登陆</button>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    function login(){
        var username = $("#username").val();
        if(username==undefined||username.trim()==""){
            $("#mesg").text("对不起,用户名不能为空");
            return;
        }

        var password = $("#password").val();
        if(password==undefined||password.trim()==""){
            $("#mesg").text("对不起,密码不能为空");
            return;
        }

        $.ajax({
            url:"login",
            type:"post",
            dataType:"json",
            data:{"username":username,"password":password},
            success:function(data){
                console.info(data)
                if(data.code==0){
                    $("#mesg").text(data.mes);

                }else{
                    location.href="tomain";
                }
            }

        })
    }

</script>
</html>
